<template>
    <el-table :data="tableData" :default-sort="{ prop: 'date', order: 'descending' }" style="width: 100%">
        <el-table-column prop="username" label="登录账号" width="180" />
        <el-table-column prop="iped" label="上次登入ip" width="180" />

        <el-table-column prop="timed" label="上次登陆时间" sortable />
        <el-table-column prop="ip" label="本次登入ip" />
        <el-table-column prop="time" label="本次登入时间" />
    </el-table>
</template>
<script setup>
import { onMounted, ref } from 'vue'
import * as api from '@/api/index.js'
// import { useLocalStorage } from '@vueuse/core';
import { useLogin } from '../../../store/cart'
import { storeToRefs } from 'pinia'
// import { flatTree } from '../../../methods/transition'
let userLogin = useLogin()
let { loginLog } = storeToRefs(userLogin)
const formatter = (row, column) => {
    return row.address
}
let tableData = ref([])
onMounted(async () => {
    let token = sessionStorage.getItem('qf-token')
    let res = await api.getLoginLog(token)
    userLogin.$patch((state) => {
        state.loginLog = res.data.data
    })
    // console.log(loginLog.value[0]);
    loginLog.value.forEach(item => {
        let obj = {
            username: item.username,
            iped: item.lastLogin.ip,
            timed:item.lastLogin.loginTime,
            ip:item.nowLogin.ip,
            time:item.nowLogin.loginTime
        }
        tableData.value.push(obj)
    });
})

</script>
<script>
export default{
    meta:{
        title: 'glsy', name: '管理首页',
        iconfont:'#icon-shouye'
        
    }
}

</script>